// pages/myinfo/personmsg/myname/myname.js
var app = getApp();
const publics = require('../../../../utils/public.js');
const md5 = require('../../../../utils/md5.js');
const http = require('../../../../utils/http.js');

Page({

    /**
     * 页面的初始数据
     */
    data: {
        placeText: '',
        btnId: '',
        inputValue: ''
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
       // console.log(options)
        this.setData({
            placeText: options.placeText,
            btnId: options.id
        })
        wx.setNavigationBarTitle({
            title: options.title,
        })
    },
    inputValue(e) {
        var nickname = e.detail.value;
        //console.log(nickname)
        this.setData({
            inputValue: nickname
        })
        wx.setStorageSync('nickname', nickname)
    },
    Submission() {
        var _this = this
        // 更新昵称
        var token = wx.getStorageSync('token')
        var nickname = wx.getStorageSync('nickname')
        //console.log('名字：' + _this.data.inputValue)
        var data = {
            method: 'User.nickname',
            token: token,
            nickname: _this.data.inputValue
        }
        var arr = http.sorts(data)
        data.sign = md5.hex_md5(arr)
        http._post(data, res => { 
            console.log(res) 
            wx.showToast({
                title: res.data.msg,
                icon: 'none',
                duration: 1000
            })
            setTimeout(() => {
                wx.navigateBack({
                    url: '/pages/myinfo/personmsg/personmsg'
                })
            }, 1000)
        })
       
       
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})